package svc

import (
	ut "github.com/go-playground/universal-translator"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"wave-service/server/app/internal/config"
	"wave-service/server/app/models"
	"wave-service/server/app/validate"
)

type ServiceContext struct {
	Config               config.Config
	VisitorsModel        models.CusVisitorsModel
	VisitorDetailsModel  models.CusVisitorDetailsModel
	VisitorContactsModel models.CusVisitorContactsModel
	MessagesModel        models.CusMessagesModel
	SendQueuesModel      models.CusSendQueuesModel
	IpBlacklistsModel    models.CusIpBlacklistsModel
	RepliesModel         models.CusRepliesModel
	Cache                *redis.Redis
	ValidatorTrans       ut.Translator
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewMysql(c.Mysql.DataSource)
	return &ServiceContext{
		Config:               c,
		VisitorsModel:        models.NewCusVisitorsModel(conn, c.CacheRedis),
		VisitorDetailsModel:  models.NewCusVisitorDetailsModel(conn, c.CacheRedis),
		VisitorContactsModel: models.NewCusVisitorContactsModel(conn, c.CacheRedis),
		MessagesModel:        models.NewCusMessagesModel(conn, c.CacheRedis),
		SendQueuesModel:      models.NewCusSendQueuesModel(conn, c.CacheRedis),
		IpBlacklistsModel:    models.NewCusIpBlacklistsModel(conn, c.CacheRedis),
		RepliesModel:         models.NewCusRepliesModel(conn, c.CacheRedis),
		Cache:                redis.New(c.CacheRedis[0].Host),
		ValidatorTrans:       validate.InitTrans(),
	}
}
